package tij4.concurrent.exercise.ex05;

import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class P05Main01 {

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newCachedThreadPool();
        ArrayList<Future<Integer>> result = new ArrayList<>();

        for (int i = 0; i < 15; i++) {
            result.add(executorService.submit(new Practice01(15)));
        }

        for (Future<Integer> integerFuture : result){
            try {
                System.out.println(integerFuture.get());
            } catch (InterruptedException e) {
                System.out.println(e);
                return;
            } catch (ExecutionException e) {
                System.out.println(e);
            } finally {
                executorService.shutdown();
            }
        }
    }
}
